﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using Newtonsoft.Json;
using SaleManagement.Models;
using System.Windows.Forms;
using SaleManagement.modules;
using System.Net;
using System.Collections.Specialized;
using SaleManagement.Common;

namespace SaleManagement.Controllers
{
    
    class BranchsController
    {
        private Branchs_Model objModel = new Branchs_Model();
        private Status_Model status ;
        private Error_Model error;
        private frmAdd_Edit_Branch frm;
        private usBranchList frmbranchlist ;
        public String mesager = "";
        

        public void setfrom(frmAdd_Edit_Branch form)
        {
            this.frm = form;
        }
        public List<Branchs_Model> select(int shopid)
        {
         return objModel.select(shopid);
        }

        public void insert_branchs(String name, String address,String phone)
        {
            int warehourse_id = 2;
            int shop_id=2;
            objModel.name = name;
            objModel.shop_id = shop_id;
            objModel.warehourse_id = warehourse_id;
            objModel.address = address;
            objModel.phone = phone;
            objModel.insert(objModel, shop_id);
           
           
           

        }















        
        //public Branchs_Model get_data(String name,String address,String phone)
        //{
        //    this.objModel.Name = name;
        //    this.objModel.Address = address;
        //    this.objModel.Phone = phone;

        //    return objModel;
            
            //string url = "http://192.168.0.104/sale-server/public/1/branch/register";
            //using(WebClient client = new WebClient())
            //{
            //    NameValueCollection post_data = new NameValueCollection() { 
            //    {"name",name},
            //    {"warehourse_id", warehourse_id},
            //    {"shop_id",shop_id},
            //    {"address",address},
            //    {"phone",phone},
            //    };
            //    String pagesoucer = Encoding.UTF8.GetString(client.UploadValues(url,"POST",post_data));
            //    bool status = pagesoucer.Contains("status");
            //    if (status == true)
            //    {
            //        Status_Model stt = JsonConvert.DeserializeObject<Status_Model>(pagesoucer);
            //        mesager = stt.Status;
            //        treck = true;
            //    }
            //    else
            //    {
            //        Error_Model err = JsonConvert.DeserializeObject<Error_Model>(pagesoucer);
            //        mesager = err.Error_code;
            //        treck = false;
            //    }
            //};
            
        

        //public bool Edit_Branchs(String name, String warehourse_id, String address, String phone)
        //{
        //    bool treck = false;
        //    int id =Convert.ToInt32(frmbranchlist.Id_Branch.ToString());
        //    string url = "http://192.168.0.104/sale-server/public/"+id+"/branch/edit";
        //    using (WebClient client = new WebClient())
        //    {
        //        NameValueCollection post_data = new NameValueCollection() { 
        //        {"name",name},
        //        {"warehourse_id", warehourse_id},
        //        {"address",address},
        //        {"phone",phone},
        //        };
        //        String pagesoucer = Encoding.UTF8.GetString(client.UploadValues(url, "POST", post_data));
        //        bool status = pagesoucer.Contains("status");
        //        if (status == true)
        //        {
        //            Status_Model stt = JsonConvert.DeserializeObject<Status_Model>(pagesoucer);
        //            mesager = stt.Status;
        //            treck = true;
        //        }
        //        else
        //        {
        //            Error_Model err = JsonConvert.DeserializeObject<Error_Model>(pagesoucer);
        //            mesager = err.Error_code;
        //            treck = false;
        //        }
        //    };
        //    return treck;
        //}
    }
}
